#include<bits/stdc++.h>
using namespace std;
string s1 , s2;
int mp[27] = {0};
void dfs(int l , int r){
	if(l > r){
		return;
	}
	int minn = 0x7ffff;
	int m;
	for(int i = l ; i <= r ; i++){
		if(mp[s1[i] - 'A'] < minn){
			minn = mp[s1[i] - 'A'];
			m = i;
		}
	}
	cout << s1[m];
	dfs(l , m - 1);
	dfs(m + 1 , r);
}
int main(){
	cin >> s1 >> s2;
	int len = s1.length();
	for(int i = 0 ; i < len ; i++){
		mp[s2[i] - 'A'] = i;
	}
	dfs(0 , len - 1);
	return 0;
}
